{extend name='common/content' /}

{block name="button"}
<div class="nowrap pull-right" style="margin-top:10px">
    {if auth("$classuri/statusAll")}
    <button type="button" class="layui-btn" id="statusAll">批量审核</button>
    {/if}
    {if auth("$classuri/statusCancelAll")}
    <button type="button" class="layui-btn layui-btn-normal" id="statusCancelAll">取消审核</button>
    {/if}
    <button data-open='{:url("$classuri/add")}' data-title="添加" class='layui-btn layui-btn-small'><i
            class='fa fa-plus'></i> 添加
    </button>
    <button data-update data-field='delete' data-action='{:url("$classuri/del")}'
            class='layui-btn layui-btn-small layui-btn-danger'><i class='fa fa-remove'></i> 删除
    </button>
</div>
{/block}

{block name="content"}

<script type="text/javascript" src="__STATIC__/admin/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/admin/js/ueditor/ueditor.all.min.js"></script>

<!-- 表单搜索 开始 -->
<form class="animated form-search" action="__SELF__" onsubmit="return false" method="get">

    <div class="row">

        <div class="col-xs-3">
            <div class="form-group">
                <input type="text" name="truename" value="{$Think.get.truename|default=''}" placeholder="传承人名称"
                       class="input-sm form-control">
            </div>
        </div>
        
        <div class="col-xs-3">
            <div class="form-group">
                <input type="text" name="admin_id" value="{$Think.get.admin_id|default=''}" placeholder="管理员名称"
                       class="input-sm form-control">
            </div>
        </div>

        <div class="col-xs-3">
            <div class="form-group">
                <input type="text" name="phone" value="{$Think.get.phone|default=''}" placeholder="手机号"
                       class="input-sm form-control">
            </div>
        </div>

        <div class="col-xs-3">
            <div class="form-group">
            <select name='aid' class='input-sm form-control'>
                <option value="">所属地区</option>
                {foreach $areaList as $val}
                {eq name='val.area_id' value='$Think.get.aid|default=0'}
                <option selected  value='{$val.area_id}'>{$val.spl}{$val.area_name}</option>
                {else/}
                <option  value='{$val.area_id}'>{$val.spl}{$val.area_name}</option>
                {/eq}
                {/foreach}
            </select>
            </div>
        </div>

        <div class="col-xs-1">
            <div class="form-group">
                <button type="submit" class="btn btn-sm btn-white"><i class="fa fa-search"></i> 搜索</button>
            </div>
        </div>
    </div>
</form>
<!-- 表单搜索 结束 -->

<form onsubmit="return false;" data-auto="" method="POST">
    <input type="hidden" value="resort" name="action"/>
    <div class="layui-form">
    <table class="table table-hover">
        <thead>
        <tr>
            <th>
                <input data-none-auto="" data-check-target='.list-check-box' lay-skin="primary" lay-filter="allChoose" type="checkbox">
            </th>
            <th class='text-center'>ID</th>
            <th class='text-center'>传承人名称</th>
            <th class='text-center'>管理员</th>
            <th class='text-center'>地区</th>
            <th class='text-center'>手机号码</th>
            <th class='text-center'>邮箱</th>
            <!--<th class='text-center'>登录次数</th>
            <th class='text-center'>最后登录</th>-->
            <!-- <th class='text-center'>类型</th> -->
            <!-- <th class='text-center'>分类</th> -->
            <!-- <th class='text-center'>已授权限</th> -->
            <th class='text-center'>状态</th>
            <th class='text-center'>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach $list as $key=>$vo}
        <tr>
            <td class=''>
                <input class="list-check-box" value='{$vo.id}' lay-skin="primary" type='checkbox'/>
            </td>
            <td class='text-center'>{$vo.id}</td>
            <td class='text-center'>{$vo.truename}</td>
            <td class='text-center'>{$vo.admin_id|get_model_value='Member','username'}</td>
            <td class='text-center'>{$vo.aid|get_ext_title='Area', 'area_name'}</td>
            <td class='text-center'>{$vo.phone|default="<span style='color:#ccc'>还没有设置手机号码</span>"}</td>
            <td class='text-center'>{$vo.mail|default="<span style='color:#ccc'>还没有设置邮箱</span>"}</td>
            <!--<td class='text-center'>{$vo.login_num|default="<span style='color:#ccc'>从未登录</span>"}</td>
            <td class='text-center'>{$vo.login_at|format_time|default="<span style='color:#ccc'>从未登录</span>"}</td>-->
            <!-- <td class='text-center'>{$vo.typename}</td> -->
            <!-- <td class='text-center'>{$vo.storeclass}</td> -->
            <!-- <td class='text-center'>{$vo.auth_name}</td> -->
            <td class='text-center'>
                {if $vo.status eq 1}
                <span style="color:#090">已审核</span>
                {else/}
                <span>未审核</span>
                {/if}
            </td>
            <td class='text-center nowrap'>

                <div class="layui-btn-group">
                    {if auth("/client") and $vo['admin_id']}
                    <a type="button" href='javascript:var url="/client?code={:base64_encode(encrypt($vo["id"], get_auth_key()))}";window.open(url);window.location.reload();' data-code="{$vo.id}" class="layui-btn layui-btn-primary layui-btn-small ">管理</a>
                    {/if}

<!--                     {if auth("$classuri/auth")}
                    <button type="button" data-modal='{:url("$classuri/auth")}?id={$vo.id}' class="layui-btn layui-btn-primary layui-btn-small">授权</button>
                    {/if} -->

                    <!-- {if auth("$classuri/pass")}
                    <button type="button" data-modal='{:url("$classuri/pass")}?id={$vo.id}' class="layui-btn layui-btn-primary layui-btn-small">密码</button>
                    {/if} -->

                    {if $vo.status eq 1 and auth("$classuri/forbid")}
                    <button type="button" data-update="{$vo.id}" data-field='status' data-value='0' data-action='{:url("$classuri/forbid")}' class="layui-btn layui-btn-primary layui-btn-small">取消审核</button>
                    {elseif auth("$classuri/resume")}
                    <button type="button" data-update="{$vo.id}" data-field='status' data-value='1' data-action='{:url("$classuri/resume")}' class="layui-btn layui-btn-primary layui-btn-small">通过审核</button>
                    {/if}

                    {if auth("$classuri/edit")}
                    <button type="button" data-open='{:url("$classuri/edit")}?id={$vo.id}' class="layui-btn layui-btn-primary layui-btn-small"><i class="layui-icon"></i></button>
                    {/if}

                    {if auth("$classuri/del")}
                    <button type="button" data-update="{$vo.id}" data-field='delete' data-action='{:url("$classuri/del")}' class="layui-btn layui-btn-primary layui-btn-small"><i class="layui-icon"></i></button>
                    {/if}
                </div>
            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>
    </div>
    {if isset($page)}<p>{$page}</p>{/if}
</form>

<script>window.form.render();</script>

<script>
    layui.use('table', function() {
        var table = layui.table,form = layui.form, $ = layui.jquery;

        //全选
        form.on('checkbox(allChoose)', function(data){
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function(index, item){
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });

        $('#statusAll').click(function(){
            layer.confirm('确认要审核选中的数据吗？', {icon: 3}, function(index) {
                layer.close(index);
                // var checkStatus = table.checkStatus('content'); //content即为参数id设定的值
                // console.log($('.layui-form-checked'));return false;
                var ids = [];
                $($('.layui-form-checked')).each(function (i, o) {
                    // console.log($(o).prev().attr('value'));return false;
                    ids.push($(o).prev().attr('value'));
                });
                // console.log(ids);return false;
                if(ids==''){
                    layer.msg('请选择要审核的数据！', {time: 1000, icon: 2});
                    return false;
                }
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('statusAll')}", {ids: ids,catid:'{:input("catid")}'}, function (data) {
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg(data.msg, {time: 1000, icon: 1});
                        window.location.reload();
                        tableIn.reload({where:{catid:'{:input("catid")}'}});
                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 2});
                    }
                });
            });
        })

        $('#statusCancelAll').click(function(){
            layer.confirm('确认要取消审核选中的数据吗？', {icon: 3}, function(index) {
                layer.close(index);
                // var checkStatus = table.checkStatus('content'); //content即为参数id设定的值
                var ids = [];
                $($('.layui-form-checked')).each(function (i, o) {
                    // console.log($(o).prev().attr('value'));return false;
                    ids.push($(o).prev().attr('value'));
                });
                if(ids==''){
                    layer.msg('请选择要取消审核的数据！', {time: 1000, icon: 2});
                    return false;
                }
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('statusCancelAll')}", {ids: ids,catid:'{:input("catid")}'}, function (data) {
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg(data.msg, {time: 1000, icon: 1});
                        window.location.reload();
                        tableIn.reload({where:{catid:'{:input("catid")}'}});
                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 2});
                    }
                });
            });
        })

    });
</script>
{/block}